/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DAOS.DAOSADMINISTRACION;

import Entidades.EntidadesAdministracion.Administrador;
import java.util.List;
import javax.ejb.Stateless;
import javax.ejb.LocalBean;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author daniel
 */
@Stateless
@LocalBean
public class AdministradorDAOS {

    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
   @PersistenceContext
    EntityManager em;
    public void crear(Administrador ad) {
        em.persist(ad);
    }

    public void actualizar(Administrador ad) {
        em.merge(ad);
    }

    public void borrar(Integer id) {
        Administrador adm = em.find(Administrador.class, id);
        em.remove(adm);
    }

    public void guardar(Administrador ad) {
        if (ad.getIdAdministrador() == null) {
            crear(ad);
        } else {
            actualizar(ad);
        }
    }

    public List<Administrador> BuscarTodosAdministrador() {
        return em.createNamedQuery("Administrador.findAll", Administrador.class).getResultList();
    }

    public List<Administrador> BuscarAdministrador(String cadena) {
        return em.createNamedQuery("Administrador.findIdAdministrador", Administrador.class)
                .setParameter("administrador", cadena).getResultList();
    }
  
}
